package com.wicket.okrapp.base.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wicket.okrapp.base.service.MOmsAchievementTypeService;
import com.wicket.okrapp.base.service.dto.req.*;
import com.wicket.okrapp.common.dto.FieldInfo;
import com.wicket.okrapp.common.exception.BizException;
import com.wicket.okrapp.common.util.CommonFunctionHelper;
import com.wicket.okrapp.dal.mapper.mbg.OmsAchievementTypeMapper;
import com.wicket.okrapp.dal.po.mbg.OmsAchievementType;

import java.util.*;
import java.util.ArrayList;
//import com.wicket.okrapp.base.service.dto.res.*;

import org.apache.skywalking.apm.toolkit.trace.Tag;
import org.apache.skywalking.apm.toolkit.trace.Tags;
import org.apache.skywalking.apm.toolkit.trace.Trace;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author ：
 * @since 2022/1/19 15:39
 * 
 *
 * @version 1.0
 */
@Service
public class MOmsAchievementTypeServiceImpl
  extends ServiceImpl<OmsAchievementTypeMapper, OmsAchievementType>
  implements MOmsAchievementTypeService {

  @Autowired
  OmsAchievementTypeMapper omsAchievementTypeMapper;
/**
   * 3-10-02新增成果类型[9098]
   * gen by moon at 4/3/2024, 1:42:51 PM
   */
 @Trace(operationName = "3-10-02新增成果类型")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  String  addAchievementType(OmsAchievementType omsAchievementType) {
     omsAchievementType.setAchievementTypeId(CommonFunctionHelper.getUid());//DISTRIBUTED_ID
omsAchievementType.setIsArchive("FALSE");
omsAchievementType.setOperationInductionId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecInductionRecordId());//CURRENT_INDUCTIONID
omsAchievementType.setCreateInductionId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecInductionRecordId());//CURRENT_INDUCTIONID
if(omsAchievementType!=null && omsAchievementType.getSubjectLifeCycle()!=null &&  omsAchievementType.getSubjectLifeCycle().equals("CURRENTLY_VALID")) {
            omsAchievementType.setReleaseInductionId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecInductionRecordId());//RELEASED_CURRENT_INDUCTIONID
          }
omsAchievementType.setOperateTime(CommonFunctionHelper.getCurrentTime());//SYSTEM_CURRENT_TIME
omsAchievementType.setCreateTime(CommonFunctionHelper.getCurrentTime());//SYSTEM_CURRENT_TIME
if(omsAchievementType!=null && omsAchievementType.getSubjectLifeCycle()!=null && omsAchievementType.getSubjectLifeCycle().equals("CURRENTLY_VALID")){
             omsAchievementType.setReleaseTime(CommonFunctionHelper.getCurrentTime());//RELEASE_SYSTEM_CURRENT_TIME
            }
omsAchievementType.setIsValid("FALSE");
     if(super.save(omsAchievementType)){
        return omsAchievementType.getAchievementTypeId();
     }else {
        return "-1";
     }
    
  }
/**
   * 3-10-02查询成果类型列表[9101]
   * gen by moon at 4/3/2024, 6:42:41 PM
   */
 @Trace(operationName = "3-10-02查询成果类型列表")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  List<OmsAchievementType>  queryAchievementTypeList(QueryAchievementTypeListReq reqDto) {
     
        try {
            QueryWrapper<OmsAchievementType> queryWrapper = new QueryWrapper<>();
            reqDto.setIsValid("FALSE");
            
            Map<String, Object> fieldInfoMap = null;
            fieldInfoMap = CommonFunctionHelper.objectToMapForLamBda(reqDto);
            List<FieldInfo> compareList = CommonFunctionHelper.getRangeField(OmsAchievementType.class);
            CommonFunctionHelper.buildQueryWrapperCompare(queryWrapper, compareList, fieldInfoMap);
            List<FieldInfo> likeList = CommonFunctionHelper.getLikeFiled(OmsAchievementType.class);
            CommonFunctionHelper.buildQueryWrapperLike(queryWrapper,likeList,fieldInfoMap);
            likeList.addAll(compareList);
            CommonFunctionHelper.buildQueryWrapperEq(queryWrapper, fieldInfoMap,likeList);
            List<FieldInfo> orderList = CommonFunctionHelper.getOrderList(OmsAchievementType.class);
            //CommonFunctionHelper.buildQueryWrapperOrder(queryWrapper, orderList);

            return ((List<OmsAchievementType>) super.list(queryWrapper));
        } catch (Exception e) {
            e.printStackTrace();
            throw new BizException("-1",e,false);
        }
  }
/**
   * 3-10-02查询成果类型详情[9102]
   * gen by moon at 4/3/2024, 1:42:58 PM
   */
 @Trace(operationName = "3-10-02查询成果类型详情")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  OmsAchievementType  queryAchievementTypeDetail(QueryAchievementTypeDetailReq reqDto) {
     
        try {
         reqDto.setIsValid("FALSE");
            QueryWrapper<OmsAchievementType> queryWrapper = new QueryWrapper<>();
            Map<String, Object> fieldInfoMap = null;
            fieldInfoMap = CommonFunctionHelper.objectToMapForLamBda(reqDto);
            CommonFunctionHelper.buildQueryWrapperEq(queryWrapper, fieldInfoMap, new ArrayList<>());
            queryWrapper.orderByDesc("create_time");
            List<OmsAchievementType> retList = super.list(queryWrapper);
            if(retList!=null && retList.size()>0){
                OmsAchievementType retData = retList.get(0);
                
                return retData;
            }
            return null;
      } catch (Exception e) {
          e.printStackTrace();
          throw new BizException("-1",e,false);
      }
  }
/**
   * 3-10-02修改成果类型[9099]
   * gen by moon at 4/3/2024, 6:42:39 PM
   */
 @Trace(operationName = "3-10-02修改成果类型")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  boolean  updateAchievementType(OmsAchievementType omsAchievementType) {
     omsAchievementType.setOperationInductionId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecInductionRecordId());//CURRENT_INDUCTIONID
if(omsAchievementType!=null && omsAchievementType.getSubjectLifeCycle()!=null &&  omsAchievementType.getSubjectLifeCycle().equals("CURRENTLY_VALID")) {
            omsAchievementType.setReleaseInductionId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecInductionRecordId());//RELEASED_CURRENT_INDUCTIONID
          }
if(omsAchievementType!=null && omsAchievementType.getSubjectLifeCycle()!=null && omsAchievementType.getSubjectLifeCycle().equals("ARCHIVING")) {
              omsAchievementType.setArchiveInductionId(CommonFunctionHelper.getBaseInfoFromLocal().getSpecInductionRecordId());//ARCHIVE_CURRENT_INDUCTIONID
          }
omsAchievementType.setOperateTime(CommonFunctionHelper.getCurrentTime());//SYSTEM_CURRENT_TIME
if(omsAchievementType!=null && omsAchievementType.getSubjectLifeCycle()!=null && omsAchievementType.getSubjectLifeCycle().equals("CURRENTLY_VALID")){
             omsAchievementType.setReleaseTime(CommonFunctionHelper.getCurrentTime());//RELEASE_SYSTEM_CURRENT_TIME
            }
if(omsAchievementType!=null && omsAchievementType.getSubjectLifeCycle()!=null && omsAchievementType.getSubjectLifeCycle().equals("ARCHIVING")) {
              omsAchievementType.setArchiveTime(CommonFunctionHelper.getCurrentTime());//HISTORICAL_ARCHIVING
          }
        return super.updateById(omsAchievementType);
  }
/**
   * 3-10-02删除成果类型[9100]
   * gen by moon at 4/3/2024, 6:42:40 PM
   */
 @Trace(operationName = "3-10-02删除成果类型")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  boolean  deleteAchievementType(String achievementTypeId ) {

      return super.removeById(achievementTypeId);
  }
/**
   * 3-10-02批量查询成果类型By主键[9267]
   * gen by moon at 4/5/2024, 8:58:28 PM
   */
 @Trace(operationName = "3-10-02批量查询成果类型By主键")
 @Tags({@Tag(key = "参数",value = "arg[0]"),
 @Tag(key = "返回值",value = "returnedObj")})
  @Override
  @Transactional(rollbackFor=Exception.class)
  public  List<OmsAchievementType>  batchQueryAchievementTypeByEntity(BatchQueryAchievementTypeByEntityReq reqDto) {

        try {
            QueryWrapper<OmsAchievementType> queryWrapper = new QueryWrapper<>();

            if(reqDto.getAchievementTypeList()==null || reqDto.getAchievementTypeList().isEmpty()){
                    return new ArrayList<>();
                }
        queryWrapper.in("achievement_type_id", reqDto.getAchievementTypeList());
            Map<String, Object> fieldInfoMap = null;
            fieldInfoMap = CommonFunctionHelper.objectToMapForLamBda(reqDto);
            List<FieldInfo> compareList = CommonFunctionHelper.getRangeField(OmsAchievementType.class);
            CommonFunctionHelper.buildQueryWrapperCompare(queryWrapper, compareList, fieldInfoMap);
            List<FieldInfo> likeList = CommonFunctionHelper.getLikeFiled(OmsAchievementType.class);
            CommonFunctionHelper.buildQueryWrapperLike(queryWrapper,likeList,fieldInfoMap);
            likeList.addAll(compareList);
            CommonFunctionHelper.buildQueryWrapperEq(queryWrapper, fieldInfoMap,likeList);
            List<FieldInfo> orderList = CommonFunctionHelper.getOrderList(OmsAchievementType.class);
            //CommonFunctionHelper.buildQueryWrapperOrder(queryWrapper, orderList);

            return ((List<OmsAchievementType>) super.list(queryWrapper));
        } catch (Exception e) {
            e.printStackTrace();
            throw new BizException("-1",e,false);
        }
  }
}
